package com.keba.lamp.complaint.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.keba.basic.annotation.log.WebLog;
import com.keba.basic.base.R;
import com.keba.basic.base.request.PageParams;
import com.keba.basic.interfaces.echo.EchoService;
import com.keba.lamp.complaint.enumeration.AccountTypeEnum;
import com.keba.lamp.complaint.vo.param.AccountPrepaymentParamVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import com.keba.basic.base.controller.SuperController;
import com.keba.lamp.complaint.service.AccountPrepaymentService;
import com.keba.lamp.complaint.entity.AccountPrepayment;
import com.keba.lamp.complaint.vo.save.AccountPrepaymentSaveVO;
import com.keba.lamp.complaint.vo.update.AccountPrepaymentUpdateVO;
import com.keba.lamp.complaint.vo.result.AccountPrepaymentResultVO;
import com.keba.lamp.complaint.vo.query.AccountPrepaymentPageQuery;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 前端控制器
 * 预付款账户
 * </p>
 *
 * @author twg
 * @date 2025-05-15 20:32:18
 * @create [2025-05-15 20:32:18] [twg] [代码生成器生成]
 */
@Slf4j
@RequiredArgsConstructor
@Validated
@RestController
@RequestMapping("/accountPrepayment")
@Tag(name = "预付款账户")
public class AccountPrepaymentController extends SuperController<AccountPrepaymentService, Long, AccountPrepayment
        , AccountPrepaymentSaveVO, AccountPrepaymentUpdateVO, AccountPrepaymentPageQuery, AccountPrepaymentResultVO> {
    private final EchoService echoService;

    @Override
    public EchoService getEchoService() {
        return echoService;
    }


    /**
     * 扣款
     */
    @Operation(summary = "账户充值、冲销")
    @PostMapping("/deduction")
    @WebLog(value = "账户充值、冲销")
    public R<Boolean> deduction(@RequestBody @Validated AccountPrepaymentParamVO accountPrepaymentParamVO) {
        superService.deduction(accountPrepaymentParamVO);
        return R.success();
    }

    @Override
    public R<List<AccountPrepaymentResultVO>> query(AccountPrepaymentPageQuery data) {
        List<AccountPrepaymentResultVO> list = super.query(data).getData();
        echoService.action(list);
        list.stream().forEach(o -> o.getEchoMap().putIfAbsent("type", AccountTypeEnum.getByCode(o.getType()).getDesc()));
        return R.success(list);
    }

    @Override
    public void handlerResult(IPage<AccountPrepaymentResultVO> page) {
        echoService.action(page.getRecords());
        page.getRecords().stream().forEach(o -> o.getEchoMap().putIfAbsent("type", AccountTypeEnum.getByCode(o.getType()).getDesc()));
    }

}


